package edu.bw.service.Impl;

import edu.bw.service.UserService;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;


/**
 * @PostConstruct:标注在初始化方法,当构造方法执行后,执行初始化方法,相当于init-method属性
 * @PreDestory:标注在销毁方法上,如果Bean是单列得话,当Spring容器关闭得时候,会调用Bean得销毁方法,相当于destory-method方法
 */
@Service
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)  //指定Bean的范围
public class UserServiceImpl05 implements UserService {

    public UserServiceImpl05(){
        System.out.println(this+"构造方法被调用");
    }

    @PostConstruct
    public void init(){
        System.out.println(this+"初始化");
    }

    @PreDestroy
    public void destory(){
        System.out.println(this+" 被销毁");
    }


}
